<?php  
    session_start();  
    $secret = "open sesame";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Whobar Demo: Authentication Results</title>
<body>
    <div style="width: 720px; margin: 10px auto;">
        <h1>Authentication Results</h1>
        <?php 
            if ($_REQUEST['whobar_errno']) {
                echo "<p style='color:red'>Error: $_REQUEST[whobar_errmsg]</p>";
            }
            elseif (empty($_REQUEST['identifier'])) {
                echo "<p style='color:red'>Authentication failed.  Missing identifier.</p>";
            }
            elseif (empty($_REQUEST['whobar_secret'])) {
                    echo "<p style='color:red'>Authentication failed.  Missing signature.</p>";
            }
            else {
                if (($_POST['whobar_secret'] == $secret)) {
                    echo "<p style='color:green'>Authentication successful! Your unique identifier is: '$_REQUEST[identifier]'</p>";
                }
                else {
                    echo "<p style='color:red'>Authentication failed.  Signature check failed.</p>";
                }
            
            }
        ?>
        <p><a href="demo/index.html">Try again</a></p>
        
        <h2>Data received by handler script</h2>
        <?php if (count($_GET)) {
        ?>        
        <h3>GET parameters:</h3>
        <pre>
        <?php
            print_r($_GET);
        } ?>
        </pre>
        <h3>POST parameters:</h3>
        <pre>
    <?php print_r($_POST); ?>
        </pre>
        <h3>Headers:</h3>
        <pre>
        <?php
            function filter_http_only($h) {
                return preg_match('/^HTTP_/', $h);
            }
            $header_keys = array_filter(array_keys($_SERVER), 'filter_http_only');
            $headers = array();
            foreach ($header_keys as $key) {
                $mapped_key = $key;
                $headers[str_replace('_', '-', preg_replace('/^HTTP_/', '', $key))] = $_SERVER[$key];
            }
            print_r($headers);
        ?>
        </pre>
        <?php if (count($_COOKIE)) {
        ?>        
        <h3>Cookies:</h3>
        <pre>
        <?php
            print_r($_COOKIE);
        } ?>
        </pre>
        <?php if (count($_SESSION)) {
        ?>        
        <h3>Session:</h3>
        <pre>
        <?php
            print_r($_SESSION);
        } ?>
        </pre>
    </div>
</body>
</html>
<?php error_log("end whobar_handler"); ?>
